#ifndef VL_BLOCK_STREAM_HPP
#define VL_BLOCK_STREAM_HPP

#include "stream.hpp"

namespace vl
{

struct blockstream : stream
{
	enum read_state
	{
		beginning,
		read_header // block_len = length of the next block
	};
	
	blockstream(stream& b);
	
	blockstream(device_buf* b);
	
	// If get() returns true, the stream is at the beginning of a block of length length().
	// length() bytes should be consumed from the stream before get() is called again.
	// 
	bool get();
	
	void put(vl::buffer const& buf);
	
	size_t length() const { return block_len; }
	
private:
	read_state cur_read_state;
	size_t     block_len;
};

}

#endif //VL_BLOCK_STREAM_HPP
